package view;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controller.DataBaseInteactor;

import model.Conference;
import model.ProgramChair;

/**
 * Makes from helps to create new conference.
 * 
 * @author Richard Lee
 * @version 52513
 *
 */
public class NewConferenceView extends JFrame {

	/**
	 * Default serial version id.
	 */
	private static final long serialVersionUID = 1626940058310661038L;
	
	/**
	 * GUI components.
	 */
	private final JLabel confTitle = new JLabel("Conference Title: ");
	private final JLabel confDate = new JLabel("Conference Date: ");
	private final JLabel manDeadLine = new JLabel("Manusciprt Deadline: ");
	private final JLabel reviewDeadLine = new JLabel("Review Deadline: ");
	private final JLabel recomDeadline = new JLabel("Recommendation Deadline: ");
	private final JLabel revisionDeadline = new JLabel("Revision Deadline: ");
	private final JTextField confDateField = new JTextField(10);
	private final JTextField manDeadLineField = new JTextField(10);
	private final JTextField reviewDeadLineField = new JTextField(10);
	private final JTextField recomDeadlineField = new JTextField(10);
	private final JTextField revisionDeadlineField = new JTextField(10);
	private final JTextField confField = new JTextField(10);
	private final JPanel titlePanel = new JPanel(new FlowLayout());
	private final JPanel confDatePanel = new JPanel(new FlowLayout());
	private final JPanel manPanel = new JPanel(new FlowLayout());
	private final JPanel reviewDeadLinePanel = new JPanel(new FlowLayout());
	private final JPanel recomDeadlinePanel = new JPanel(new FlowLayout());
	private final JPanel revisionDeadlinePanel = new JPanel(new FlowLayout());
	private final JPanel buttonPanel = new JPanel(new FlowLayout());
	private final JButton createButton = new JButton("Create");
	private final JButton cancelButton = new JButton("Cancel");
	
	/**
	 * Database interactor.
	 */
	private final DataBaseInteactor inteactor;
	
	/**
	 * The conference.
	 */
	private Conference conference;
	
	/**
	 * User id.
	 */
	private String ID;
	
	/**
	 * Constructor.
	 * 
	 * @param theInteactor Database interactor.
	 */
	public NewConferenceView(DataBaseInteactor theInteactor) {
		super("Create New Conference");
		inteactor = theInteactor;
	}
	
	/**
	 * Constructor.
	 * 
	 * @param inputID user id.
	 * @param inputPW user password.
	 * @param theInteactor Database interactor.
	 */
	public NewConferenceView(String inputID, String inputPW, DataBaseInteactor theInteactor) {
		super("Create New Conference");
		ID = inputID;
		inteactor = theInteactor;
	}
	
	/**
	 * Combine and add GUI component.
	 */
	public void makeNewConferenceView() {
		titlePanel.add(confTitle);
		titlePanel.add(confField);
		confDatePanel.add(confDate);
		confDatePanel.add(confDateField);
		manPanel.add(manDeadLine);
		manPanel.add(manDeadLineField);
		reviewDeadLinePanel.add(reviewDeadLine);
		reviewDeadLinePanel.add(reviewDeadLineField);
		recomDeadlinePanel.add(recomDeadline);
		recomDeadlinePanel.add(recomDeadlineField);
		revisionDeadlinePanel.add(revisionDeadline);
		revisionDeadlinePanel.add(revisionDeadlineField);
		buttonPanel.add(createButton);
		buttonPanel.add(cancelButton);
		JPanel p = new JPanel();
		p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
		p.add(titlePanel);
		p.add(confDatePanel);
		p.add(manPanel);
		p.add(reviewDeadLinePanel);
		p.add(recomDeadlinePanel);
		p.add(revisionDeadlinePanel);
		p.add(buttonPanel);
		add(p);
		setVisible(true);
		pack();
		setLocationRelativeTo(null);
		actions();
	}
	
	/**
	 * Add actions to buttons.
	 */
	public void actions() {
		createButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ProgramChair programchair = new ProgramChair(ID, inteactor);
				conference = new Conference(inteactor);
				conference.createConference(confField.getText() , confDateField.getText() , manDeadLineField.getText(), 
						recomDeadlineField.getText(), reviewDeadLineField.getText(), programchair);
			}
		});
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
	
	}
	
}
